package com.googlecode.groovyworks.grails;

import groovy.lang.ExpandoMetaClass;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.ActionProxyFactory;
import com.opensymphony.xwork2.DefaultActionInvocation;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;

public class GrailsActionProxyFactory implements ActionProxyFactory {
	protected Container container;

	public GrailsActionProxyFactory() {
		ExpandoMetaClass.enableGlobally();
	}

	@Inject
	public void setContainer(Container container) {
		this.container = container;
	}

	public ActionProxy createActionProxy(String namespace, String actionName,
			Map extraContext) throws Exception {
		throw new RuntimeException("Not Implemented!");
	}

	public ActionProxy createActionProxy(String namespace, String actionName,
			Map extraContext, boolean executeResult, boolean cleanupContext)
			throws Exception {
		ActionInvocation inv = new DefaultActionInvocation(extraContext, true);
		container.inject(inv);
		return new GrailsActionProxy(inv, extraContext);
	}

	public ActionProxy createActionProxy(ActionInvocation inv,
			String namespace, String actionName, Map extraContext,
			boolean executeResult, boolean cleanupContext) throws Exception {
		throw new RuntimeException("Not Implemented!");
	}
}
